package com.openapi.protocol.decode.subPackageHandle.faceSynchronization;

import com.openapi.config.JT808ServerConfig;
import exsun.jt808.data.util.FtpUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class FacePictureHandle {

    /*
   存储比对人脸图片文件至ftp服务器
    */
    public static boolean saveToFTP(JT808ServerConfig jt808ServerConfig, String fileName, String filePath, byte[] data)throws Exception{
//        boolean result = FixedThreadHandleRunnable.ftpSave(jt808ServerConfig.getJt808FtpServer(),
//                jt808ServerConfig.getJt808FtpPort(), jt808ServerConfig.getJt808FtpUserName(),
//                jt808ServerConfig.getJt808FtpPassword(), jt808ServerConfig.getJt808FtpBasePath(),
//                filePath,fileName,data,jt808ServerConfig.getJt808FtpTimeOut());
         FtpUtils.changeWorkingDirectory(jt808ServerConfig.getJt808FtpBasePath(),jt808ServerConfig.getAbsBasePath(),filePath,false);
        return  FtpUtils.storageFile(fileName,data,false);
    }

    public static String getFilePath(String phoneNum){
        return "/FacePicture/"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())
                + "/" + phoneNum;
    }

    public static String getFileName(int pictureFormat){
        return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "." + getFileType(pictureFormat);
    }

    private static String getFileType(int pictureFormat){
        if(pictureFormat==0){
            return "jpeg";
        }
        if(pictureFormat==1){
            return "tif";
        }
        if(pictureFormat==2){
            return "mp3";
        }
        if(pictureFormat==3){
            return "wav";
        }
        if(pictureFormat==3){
            return "wmv";
        }
        return "unKnow";
    }
}
